package com.jnevision.overtime.service;

import java.time.Year;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.ImmutableMap;
import com.jnevision.common.CommonQuery;
import com.jnevision.overtime.mapper.OvertimeMapper;
import com.jnevision.overtime.model.Overtime;
import com.jnevision.overtime.model.OvertimeVO;

/**
 * <p>
 * 加班申请 服务实现类
 * </p>
 *
 * @author gavin
 * @since 2019-07-14
 */
@Service
public class OvertimeServiceImpl extends ServiceImpl<OvertimeMapper, Overtime> {
    public OvertimeVO getApproveDetail(String overtimeRecordId) {
        return this.baseMapper.getApproveDetail(overtimeRecordId);
    }

    public List<OvertimeVO> getApprove(String userId) {
        return this.baseMapper.getApprove(userId);
    }

    public Float getRestTime(String userId) {
        Map<String,
            String> map = new ImmutableMap.Builder<String, String>().put("userId", userId)
                .put("start", Year.now().toString() + "-01-01 00:00:00")
                .put("end", Year.now().plusYears(1).toString() + "-01-01 00:00:00").build();
        return this.baseMapper.getRestTime(map);
    }

    public R<IPage<OvertimeVO>> page(Page<OvertimeVO> page, CommonQuery commonQuery, Integer result) {
        return R.ok(this.baseMapper.page(page, commonQuery, result));
    }

    public String overtimeDuration(CommonQuery query) {
        return this.baseMapper.overtimeDuration(query);
    }

    public List<Overtime> overtimeSlot(CommonQuery query) {
        return this.baseMapper.overtimeSlot(query);
    }

    public IPage<OvertimeVO> getRecordsByUser(Page<OvertimeVO> page, String userId) {

        return this.baseMapper.getRecordsByUser(page, userId);
    }
}
